<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <div>
            <button id="submit">登录</button>
        </div>
        <div>
            <button id="validate">获取用户信息</button>
        </div>
        <script src="https://unpkg.com/axios/dist/axios.min.js"></script>

        <script>
            const submit = document.querySelector("#submit");
            let token = "";
            submit.onclick = () => {
                axios({
                    method: "post",
                    url: "http://127.0.0.1:3000/login",
                    data: {
                        password: "admin",
                        username: "admin",
                    },
                });
            };
            const validate = document.querySelector("#validate");
            validate.onclick = () => {
                axios.defaults.withCredentials = true;
                axios({
                    method: "get",
                    url: "http://127.0.0.1:3000/user",
                });
            };
        </script>
    </body>
</html>
